source $FISH_CONFIG_HOME/lib/git.fish

function fish_right_prompt
  set_color $fish_color_autosuggestion 2> /dev/null; or set_color 555
  date "+%T"
  set_color normal
end

function fish_prompt
  set -l last_command_status $status
  set -l cwd

  if test "$theme_short_path" = 'yes'
    set cwd (basename (prompt_pwd))
  else
    set cwd (prompt_pwd)
  end

  set -l fish_logo    "->"
  set -l ahead    "+"
  set -l behind   "-"
  set -l diverged "!"
  set -l dirty    "⨯"
  set -l stash    "~"
  set -l none     "#"

  set -l normal_color     (set_color --bold normal)
  set -l success_color    (set_color --bold green)
  set -l error_color      (set_color --bold $fish_color_error 2> /dev/null; or set_color red --bold)
  # set -l directory_color  (set_color --bold magenta 2> /dev/null; or set_color brown)
  set -l directory_color  (set_color --bold blue 2> /dev/null; or set_color brown)
  set -l repository_color (set_color --bold yellow 2> /dev/null; or set_color green)

  set -l prompt_string $fish_logo

  if test "$theme_ignore_ssh_awareness" != 'yes' -a -n "$SSH_CLIENT$SSH_TTY"
    set prompt_string (whoami)"@"(hostname -s)
  end

  if test $last_command_status -eq 0
    echo -n -s $success_color $prompt_string $normal_color
  else
    echo -n -s $error_color $prompt_string $normal_color
  end

  if git_is_repo
    if test "$theme_short_path" = 'yes'
      set root_folder (command git rev-parse --show-toplevel 2> /dev/null)
      set parent_root_folder (dirname $root_folder)
      set cwd (echo $PWD | sed -e "s|$parent_root_folder/||")
    end

    echo -n -s " " $directory_color $cwd $normal_color
    echo -n -s " " $repository_color (git_branch_name) $normal_color " "
    #echo -n -s " " $repository_color (git_branch_name) $normal_color


    set -l list
    if test "$theme_stash_indicator" = yes; and git_is_stashed
      set list $list $stash
    end
    if git_is_touched
      set list $list $dirty
    end
    echo -n $list

    if test -z "$list"
      echo -n -s (git_ahead $ahead $behind $diverged $none)
    end
  else
    echo -n -s " " $directory_color $cwd $normal_color
  end

  echo -n -s " "
end
